<?php
	defined('_JEXEC') or die('Restricted access');
	$db = JFactory::getDBO();
	$query = "SELECT id, name, alias FROM #__pr_category WHERE parent_id = 0";
	$db->setQuery($query);
	$cats = $db->loadObjectList();
	
	$currCat = intval(JRequest::getVar('catid', 2));
	if(JRequest::getVar('view') == 'promotion') $currCat = 0;
?>
<div class="content-left">
    <div id="order-list-2">
        <ul class="main-order-list">
        	<?php foreach($cats as $cat){
				$cat_link = "index.php?option=com_ecommerce&view=category&catid=".$cat->id.":".$cat->alias."&Itemid=16";
				$query = "SELECT id FROM #__pr_category WHERE parent_id = ".$cat->id;
				$db->setQuery($query);
				$arrChild = $db->loadResultArray();
			?>
            <li>
                <a href="<?php echo $cat_link;?>" <?php if(($cat->id == $currCat) || (in_array($currCat, $arrChild))) echo 'class="activeCate"';?>><?php echo $cat->name;?></a>
                <ul class="sub-list-order-2" <?php if(($cat->id == $currCat) || (in_array($currCat, $arrChild))) echo 'style="display:block"';?>>
                <?php 
					$query = "SELECT id, name, alias, frost FROM #__pr_category WHERE parent_id = ".$cat->id;
					$db->setQuery($query);
					$children = $db->loadObjectList();
					foreach($children as $child){
						$child_link = "index.php?option=com_ecommerce&view=list&parent=".$cat->id.":".$cat->alias."&catid=".$child->id.":".$child->alias."&Itemid=16";
				?>
                    <li <?php if($child->frost) echo 'class="frozen-ico"';?>><a <?php if($child->id == $currCat) echo 'class="activeSubcate-2"';?> href="<?php echo $child_link;?>" <?php if($child->frost) echo 'title="Frost"';?>><?php echo $child->name;?></a></li>
                <?php }?>
                </ul>
            </li>
            <?php }?>					
        </ul>
    </div>
    <a href="index.php?option=com_ecommerce&view=promotion&Itemid=20" id="stroke-week">Ugens Slagtilbud - Klik her</a>
</div>